/**
 * Created by yangxianming on 2019/5/7.
 */

function feimeVerification(verifiesOrCancel){
    var feimaVoucherNumber = document.getElementById("feimaVoucherNumber").value;
    var feimaAmountPaid = document.getElementById("feimaAmountPaid").value;
    var storeNumber = document.getElementById("storeNumber").value;
    var productNumber = document.getElementById("productNumber").value;
    var productName = document.getElementById("productName").value;

    var reqtype;
    if(verifiesOrCancel == "verifies"){
        reqtype = "71";
    }
    if(verifiesOrCancel == "cancel"){
        reqtype = "3";
    }

    var verificationData = {
        "stationId": "ceshi",
        "voucherNumber": feimaVoucherNumber,
        "storeNumber": storeNumber,
        "reqtype": reqtype,
        "requestAccount": "1516",
        "transId":  (new Date()).getTime(),
        "signParam": "DDEBAB6995332D464CBABA34F7E8F0EB",
        "orderInfo": {
            "amountRec": feimaAmountPaid,
            "amountPaid": parseInt(feimaAmountPaid),
            "orderProducts": [{
                "lineNumber": 1,
                "productNumber": productNumber,
                "productName": productName,
                "quantity": 1,
                "initPrice": parseInt(feimaAmountPaid),
                "nowPrice": parseInt(feimaAmountPaid),
                "payMoney": 1200
            }]
        }
    };

    var saveData = {
        "whichVerifies":"feima",
        "verifiesOrCancel":verifiesOrCancel,
        "verificationData":verificationData
    };
    var xmlHttp = new XMLHttpRequest();
    xmlHttp.open("post", "/efuli/verification", true);
    xmlHttp.onreadystatechange = function(){
        if (xmlHttp.readyState==4){
            if (xmlHttp.status==200){
                var r = JSON.parse(xmlHttp.response);
                if (r["apiStatus"] == "1"){
                    alert(r["result"]);
                }else{
                    alert(r["errorMsg"]);
                }

            }else{
                alert("服务器异常");
            }
        }
    };

    xmlHttp.send(JSON.stringify(saveData));
}